package com.jichangxiu.framework.manager;

import com.jichangxiu.framework.utils.AsyncUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

@Component
public class ShutdownManager {

    private static final Logger logger = LoggerFactory.getLogger("async-task");

    @PreDestroy
    public void destroy() {
        shutdownAsyncManager();
    }

    private void shutdownAsyncManager() {
        // 停止异步执行任务
        try {
            logger.debug("【ShutdownManager】关闭后台任务线程池");
            AsyncUtils.getINSTANCE().shutdown();
        } catch (Exception ex) {
            throw new RuntimeException("【ShutdownManager】关闭后台任务线程池异常", ex);
        }
    }

}